//
//  ReportCradAnswerSheetTCell.m
//  SchoolHelper
//
//  Created by 任辰东 on 2022/8/26.
//  Copyright © 2022 JSY. All rights reserved.
//

#import "ReportCradAnswerSheetTCell.h"

#import <ImageIO/ImageIO.h>

@implementation ReportCradAnswerSheetModel
-(void)setTi_answer_img:(NSString *)ti_answer_img
{
    _ti_answer_img = [NSString stringWithFormat:@"https://yuejuanimg.jzyxxb.cn/%@",ti_answer_img];
}
@end

@interface ReportCradAnswerSheetTCell ()
@property (nonatomic, strong) UILabel *markLabel;
@end

@implementation ReportCradAnswerSheetTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(NSString *)dealAnswer:(NSString *)ti_ke_answer
{
    NSArray *answerArray = [ti_ke_answer mj_JSONObject];
    NSString *answer = [answerArray componentsJoinedByString:@""];
    return answer;
}

-(void)configCellWithModel:(ReportCradAnswerSheetModel *)model
{
    [self.titleView configViewWithTitle:model.ti_name_show];
    ////1.单选;2.多选;3.填空;4.解答
    if (model.ti_type.integerValue == 1 || model.ti_type.integerValue == 2) {
        
//        self.infoLabel.hidden = NO;
        self.contentImageView.hidden = YES;
//        self.markLabel.hidden = YES;
        self.infoLabel.text = [NSString stringWithFormat:@"%@/%.1f分",model.ti_ke_answer,model.defen.floatValue];
        
        [self.infoLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
             
            make.top.equalTo(self.titleView.mas_bottom).offset(10);
            make.left.equalTo(self.contentView).offset(15 + 4 + 8);
            make.right.equalTo(self.contentView).offset(-15);
            make.bottom.equalTo(self.contentView).offset(-10);
        }];
        
        [self.contentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
           
            make.top.equalTo(self.titleView.mas_bottom).offset(0);
            make.left.equalTo(self.contentView).offset(15);
            make.right.equalTo(self.contentView).offset(-15);
            make.height.mas_equalTo(0);
        }];
        
    }else{
       
//        self.infoLabel.hidden = YES;
        self.contentImageView.hidden = NO;
//        self.markLabel.hidden = NO;
        
//        NSString *one = [NSString stringWithFormat:@"%@: %@分",model.ti_name_show,model.defen];
        NSString *two = @"";
        if (!IsEmpty(model.one_score) && !IsEmpty(model.one_teacher_name)) {
            
            two = [NSString stringWithFormat:@"一评分 %@ %@",model.one_score,model.one_teacher_name];
        }
        
        NSString *three = model.one_teacher_time.integerValue == 0 ? @"":[NSString stringWithFormat:@"%@",[model.one_teacher_time dateStringWithFormat:@"yyyy-MM-dd HH:mm:ss"]];
        
        NSString *four = @"";
        if (!IsEmpty(model.two_score) && !IsEmpty(model.two_teacher_name)) {
            
            four = [NSString stringWithFormat:@"\n二评分 %@ %@",model.two_score,model.two_teacher_name];
        }
        
        NSString *five = model.two_teacher_time.integerValue == 0 ? @"":[NSString stringWithFormat:@"%@",[model.two_teacher_time dateStringWithFormat:@"yyyy-MM-dd HH:mm:ss"]];
        
        NSString *mark = [NSString stringWithFormat:@"%@  %@%@  %@",two,three,four,five];
        self.infoLabel.text = mark;
        
        [self.infoLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
             
            make.top.equalTo(self.titleView.mas_bottom).offset(10);
            make.left.equalTo(self.contentView).offset(15 + 4 + 8);
            make.right.equalTo(self.contentView).offset(-15);
        }];
        
        [self.contentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
           
            make.top.equalTo(self.infoLabel.mas_bottom).offset(10);
            make.left.equalTo(self.contentView).offset(15);
            make.right.equalTo(self.contentView).offset(-15);
            make.bottom.equalTo(self.contentView).offset(-10);
        }];
    }
}

-(void)setupViews
{
    self.contentView.backgroundColor = UIColorFromHex(kColorWhite);
    [self.contentView addSubview:self.titleView];
    [self.contentView addSubview:self.infoLabel];
    [self.contentView addSubview:self.contentImageView];
//    [self.contentImageView addSubview:self.markLabel];
}

-(void)setupLayout
{
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.contentView).offset(10);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(23);
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
         
        make.top.equalTo(self.titleView.mas_bottom).offset(10);
        make.left.equalTo(self.contentView).offset(15 + 4 + 8);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.titleView.mas_bottom).offset(10);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
//    [self.markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//
////        make.left.equalTo(self.contentImageView).offset(15);
//        make.right.equalTo(self.contentImageView).offset(-15);
//        make.bottom.equalTo(self.contentImageView).offset(-10);
//    }];
}

-(ReportCardTitleView *)titleView
{
    if (!_titleView) {
        _titleView = [ReportCardTitleView new];
        [_titleView configViewWithTitle:@"答题卡"];
    }
    return _titleView;
}

-(UIImageView *)contentImageView
{
    if (!_contentImageView) {
        _contentImageView = [UIImageView new];
        _contentImageView.contentMode = UIViewContentModeScaleAspectFill;
        _contentImageView.clipsToBounds = YES;
        _contentImageView.backgroundColor = UIColor.lightGrayColor;
    }
    return _contentImageView;
}

-(UILabel *)infoLabel
{
    if (!_infoLabel) {
        _infoLabel = [UILabel new];
        _infoLabel.textColor = UIColorFromHex(0x666666);
        _infoLabel.font = UIFontSize(16);
        _infoLabel.numberOfLines = 0;
    }
    return _infoLabel;
}

-(UILabel *)markLabel
{
    if (!_markLabel) {
        _markLabel = [UILabel new];
        _markLabel.textColor = UIColor.redColor;
        _markLabel.font = UIBoldFontSize(14);
        _markLabel.numberOfLines = 0;
//        _markLabel.textAlignment = NSTextAlignmentRight;
    }
    return _markLabel;
}

@end
